package com.spzx.user.service.impl;

import com.spzx.common.redis.annotation.CustomCache;
import com.spzx.user.domain.Region;
import com.spzx.user.mapper.RegionMapper;
import com.spzx.user.service.IRegionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 地区信息表 服务实现类
 * </p>
 *
 * @author gaozz
 * @since 2024-07-01
 */
@Service
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> implements IRegionService {

    @Autowired
    private RegionMapper regionMapper;

    @Override
    @CustomCache(prefix = "user:region:tree", key = "#parentCode", expiredTime = 60 * 60, randomExpired = true)
    public List<Region> treeSelect(Long parentCode) {
        return this.lambdaQuery().eq(Region::getParentCode, parentCode).list();
    }

    @Override
    public String getFullAddress(String districtCode, String address) {
        String fix = regionMapper.selectRegionDetail(districtCode);
        return fix + address;
    }
}
